﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using System.Text;

using Ordinaire.Security.Model;
using Ordinaire.Taxonomy.Model;

namespace Ordinaire.Db.Linq
{
    /// <summary>
    /// OrdinaireContext class serves as a factory class for obtaining references to all entity classes available within the library.
    /// </summary>
    public class OrdinaireContext : DataContext
    {
        #region Variables

        /// <summary>
        /// This variable is meant to be reused and can be any of the following:
        /// - The name of a file where SQL Server Express database resides.
        /// - The name of a server where a database is present. In this case the provider uses the default database for a user.
        /// - A complete connection string. LINQ to SQL just passes the string to the provider without modification.
        /// </summary>
        protected static string _fileOrServerOrConnection;

        #endregion

        #region Constructor

        /// <summary>
        /// Create new DataContext instance with fileOrServerOrConnection that is set by SetFileOrServerOrConnection().
        /// </summary>
        public OrdinaireContext() : base(_fileOrServerOrConnection) { }

        #endregion

        #region Public methods

        /// <summary>
        /// Set the fileOrServerOrConnection permanently and subsequently will be used by class empty constructor.
        /// </summary>
        /// <param name="fileOrServerOrConnection">
        /// This argument can be any of the following:
        /// - The name of a file where SQL Server Express database resides.
        /// - The name of a server where a database is present. In this case the provider uses the default database for a user.
        /// - A complete connection string. LINQ to SQL just passes the string to the provider without modification.
        /// </param>
        /// <returns>new instance of EntityFactory</returns>
        public static void SetFileOrServerOrConnection(string fileOrServerOrConnection)
        {
            _fileOrServerOrConnection = fileOrServerOrConnection;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Returns Role entity table.
        /// </summary>
        public Table<Role> Roles
        {
            get { return GetTable<Role>(); }
        }

        /// <summary>
        /// Returns UserRole entity table.
        /// </summary>
        public Table<UserRole> UserRoles
        {
            get { return GetTable<UserRole>(); }
        }

        /// <summary>
        /// Returns User entity table.
        /// </summary>
        public Table<User> Users
        {
            get { return GetTable<User>(); }
        }

        /// <summary>
        /// Returns Vocab entity table.
        /// </summary>
        public Table<Vocab> Vocabs
        {
            get { return GetTable<Vocab>(); }
        }

        #endregion
    }
}
